//
//  nameEditView.m
//  AILove
//
//  Created by 甘世清 on 2024/1/8.
//

#import "nameEditView.h"

@implementation nameEditView

- (void)SQ_UIViewForSelfView{
    self.backgroundColor = UIColor.clearColor;
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
    UIVisualEffectView* visualView = [[UIVisualEffectView alloc]initWithEffect:effect];
     visualView.frame =CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT);
      visualView.alpha = 0.92;
     [self addSubview:visualView];
    UIView * bgView = [[UIView alloc]init];
    bgView.backgroundColor = SQHexColor(@"#FFFFFF", 0.24);
    bgView.layer.cornerRadius = 12;
    bgView.layer.masksToBounds = YES;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(295);
        make.height.mas_equalTo(176);
        make.centerX.centerY.equalTo(self);
    }];
    self.oneLabel= [[UILabel alloc]init];
    self.oneLabel.text = SQNSLocalString(@"设置昵称");
    self.oneLabel.textColor = SQColor(@"#FFFFFF");
    self.oneLabel.font = FONT_BOLD(18);
    [bgView addSubview:self.oneLabel];
    [self.oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView).offset(20);
        make.centerX.equalTo(bgView);
        make.height.mas_equalTo(18);
    }];
    [bgView addSubview:self.fsTextView];
    [self.fsTextView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(bgView);
            make.top.equalTo(self.oneLabel.mas_bottom).offset(20);
            make.width.mas_equalTo(200);
            make.height.mas_equalTo(40);
    }];
  
    HeaderView * btn = [[HeaderView alloc]init];
    btn.font = FONT_MEDIUM(16);
    btn.text = SQNSLocalString(@"确定");
    btn.layer.cornerRadius = 4;
    btn.headerImage.image = SQGetImage(@"按钮背景");
    [btn.btn addTarget:self action:@selector(SQ_buttonClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(bgView.mas_bottom).offset(-20);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(263);
        make.centerX.equalTo(bgView);
    }];
    
    _guanbi = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(15, 15) midmargin:0];
    _guanbi.image = SQGetImage(@"退出图标");
    [self addSubview:self.guanbi];
    [self.guanbi mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(bgView.mas_bottom);
            make.size.mas_equalTo(45);
    }];
  
    
}
-(void)SQ_buttonClick{
    if (![self.fsTextView.formatText isNotEmpty]) {
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"请设置昵称!")];
        return;
    }
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    
    [dic setObject:self.fsTextView.formatText forKey:@"name"];
    [HttpTool post:Url5 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        UserModel * model = [ UserModel share];
        model.name = self.fsTextView.formatText;
        [UserModel updateLocalUserModel:model];
        if (self.dismissBlock) {
            self.dismissBlock();
        }  
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}

-(FSTextView*)fsTextView{
    if (!_fsTextView) {
        _fsTextView = [FSTextView textView];
        _fsTextView.font = FONT_MEDIUM(15);
        _fsTextView.textColor = UIColor.whiteColor;
        _fsTextView.placeholder =SQNSLocalString(@"请输入昵称");
        _fsTextView.placeholderColor = SQColorF5F5F5;
        _fsTextView.backgroundColor = UIColor.clearColor;
        _fsTextView.maxLength = 15;
        _fsTextView.layer.cornerRadius = 4;
        _fsTextView.layer.masksToBounds = YES;
        _fsTextView.backgroundColor = SQHexColor(@"#000000", 0.2);
    }
    return _fsTextView;
}

@end
